package br.com.news.database.services;

import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;

import br.com.news.database.daos.interfaces.IAcessoNoticiaDao;
import br.com.news.database.entities.AcessoNoticiaEntity;
import br.com.news.database.exception.DataBaseException;
import br.com.news.database.utils.GenericService;
import br.com.news.database.utils.interfaces.IGenericDao;
import br.com.news.utils.database.beans.AcessoNoticiaBean;
import br.com.news.utils.database.exception.DataBaseServiceException;
import br.com.news.utils.database.interfaces.IAcessoNoticiaServiceDb;

@Named
public class AcessoNoticiaServiceDb extends GenericService<AcessoNoticiaBean, AcessoNoticiaEntity, Long> implements IAcessoNoticiaServiceDb{

	@Inject
	private IAcessoNoticiaDao acessoNoticiaDao;

	@Override
	protected IGenericDao<AcessoNoticiaEntity, Long> getConcreteDao() {
		return this.acessoNoticiaDao;
	}
	
	@Override
	public List<AcessoNoticiaBean> maisLidasDaSemana(int qntNoticias,int idCategoria) {
		return parserEntity(acessoNoticiaDao.maisLidasDaSemana(qntNoticias, idCategoria));
	}
	
	@Override
	public void save(AcessoNoticiaBean acessoNoticiaBean) throws DataBaseServiceException {
		try {
			acessoNoticiaDao.save(parserBean(acessoNoticiaBean));
		} catch (DataBaseException e) {
			throw new DataBaseServiceException("Erro ao tentar salvar a entidade",e);
		}
	}

}
